﻿using System;

namespace Cpu6502.Opcodes
{
    class BCC : Opcode
    {
        public BCC()
        {
            this.CpuCycles = 2;
            this.AddressType = CPU.AddressType.Relative;
        }

        public override void Execute()
        {
            if (!CPU.Registers.P.C)
            {                
                // Calculate CpuCycles consumed 4 if branching across a page, 3 if not
                this.CpuCycles += ((CPU.PC & 0xFF00) != 
                    ((MemoryHelper.RelativeAddress(CPU.PC,(Int16)base.Argument)) & 0xFF00) ? 2 : 1);                                
                
                CPU.PC = MemoryHelper.RelativeAddress(CPU.PC,(Int16)base.Argument);
            }
        }      
    }
}
